#!/bin/sh
#
# Author ： hbaolong@vip.qq.com
#
# Function : 生成一本书。
#
#
#

if [ $# -ne 0 ]; then
	echo "Usage: this is a empty shell."
	exit
fi

bookno=`pwd | awk -F/ '{print $NF}'  | awk '{split($0,a,"[^0-9]+"); for(i in a) {printf a[i]};}'`

bookname=`pwd | awk -F/ '{print $NF}' `

#echo $bookno

# 是否存在备份文件

if ls $bookname"_"*.md >/dev/null ;then 

	tag=`ls $bookname"_"*.md |awk -F_ '{print $2}' | sed -e "s/.md//g"`

	mdfile=`ls $bookname"_"*.md`
else
	echo "请输入本书的tag，q 退出"
	read tag
	if [ -e s.md ]; then
		mdfile="s.md"
	else
		echo "没有书籍文件"
		exit -1;
	fi
fi

echo $tag

today=`date -I`

formatbooktoline  $mdfile $today $tag 100000

